<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>解构赋值</h2>
</body>
<script>
    //对象的解构
    let obj = {
        name: 'alice',
        age: 20,
        address: '北京'
    }

    //  let aaa='age'
    //  let name=obj.name
    //  let age=obj.age

    //    let {name:username,age:nianling,address:dizhi}=obj

    //    console.log(username)
    //    console.log('年龄：',nianling)
    //    console.log(dizhi)

    //数组解构
    let arr = [100, 200, 300, 'hello'];
    let [first, second] = arr
    console.log(first)
    console.log(second)
    let res = {
        code: 0,
        msg: '成功登录',
        data: {
            token: '23qtw3jkwtjlk34j6tklw456jlk45w',
            username: 'admin',
            password: '123456',
            info: ['运动', '本科', '程序员']
        }
    }

    res.data.info[0]
    let {
        code,
        msg,
        data: {
            token,
            username,
            info: [sport, xueli, career]
        }
    } = res
    console.log('token：', token)
    console.log('sport', sport)
    console.log('xueli', xueli)
</script>

</html>